package pms.sg.action;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import pms.sg.service.NewSGService;
import pms.common.value.ProjectValue;
import pms.common.value.sgNewValue;
import pms.common.value.sgUserValue;
import pms.common.value.sgListValue;
import com.opensymphony.xwork2.ActionSupport;

public class NewSGAction extends ActionSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private NewSGService newSGService;
	public NewSGService getNewSGService() {
		return newSGService;
	}
	public void setNewSGService(NewSGService newSGService) {
		this.newSGService = newSGService;
	}
	
	private sgNewValue sgnew= new sgNewValue();
	private sgListValue zhlist;
	private Collection<sgListValue> Zhlists;
	private sgUserValue user;
	
	private static final int BUFFER_SIZE = 16 * 1024;

	public sgUserValue getUser() {
		return user;
	}
	public void setUser(sgUserValue user) {
		this.user = user;
	}
	
	public static int getBUFFER_SIZE() {
		return BUFFER_SIZE;
	}

	@SuppressWarnings("unchecked")
	public List getTestList() {
		List l_array = new ArrayList();
		l_array.add("0");
		l_array.add("1");
		l_array.add("2");
		return l_array;
	}
	@SuppressWarnings("unchecked")
	public List getMonthArray() {
		List l_list = new ArrayList();
		for (int i=0;i<12;i++) {
			if (i<9) {
				l_list.add(i,"0" + (i+1));
			} else {
				l_list.add(i,"" + (i+1));
			}
		}
		return l_list;
	}
	
	@SuppressWarnings("unchecked")
	public List getDayArray() {
		List l_list = new ArrayList();
		for (int i=0;i<31;i++) {
			if (i<9) {
				l_list.add(i,"0" + (i+1));
			} else {
				l_list.add(i,"" + (i+1));
			}
		}
		return l_list;
	}
	//プロジェクト
	public List<ProjectValue> getProjectList() {
		return newSGService.getProjectList();
	}
	// 所属テーマ
	@SuppressWarnings("unchecked")
	public List<HashMap> getFunctionArray() throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException {   
        return newSGService.getFunctionArray();
    }
	//テスト段階
	@SuppressWarnings("unchecked")
	public List<HashMap> getTestlvlArray() throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException {   
        return newSGService.getTestlvlArray();
    }
	// 検出側
	@SuppressWarnings("unchecked")
	public List<HashMap> getTestPartArray() throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException {   
        return newSGService.getTestPartArray();
    }
	// 検出者
	@SuppressWarnings("unchecked")
	public List<HashMap> getTesterArray() throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException {   
        return newSGService.getUserArray();
    }

	// 修正担当
	@SuppressWarnings("unchecked")
	public List<HashMap> getModifyArray() throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException {   
        return newSGService.getUserArray();
    }
	// ステータス
	@SuppressWarnings("unchecked")
	public List<HashMap> getStatusArray() throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException {   
        return newSGService.getStatusArray();
    }
	
	// 障害要因
	@SuppressWarnings("unchecked")
	public List<HashMap> getReasonArray() throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException {
        return newSGService.getReasonArray();
    }

	@Override
	public String execute() throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException {

		Zhlists = new ArrayList<sgListValue>();
		return SUCCESS;
	}
	
	public String insertData() throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException {
		
		try {
			newSGService.doInsert(sgnew);
		} catch (Exception e) {
			e.printStackTrace();
		}
		sgnew = new sgNewValue();
		return SUCCESS;
	}
	
	public sgListValue getZhlist() {
		return zhlist;
	}
	public void setZhlist(sgListValue zhlist) {
		this.zhlist = zhlist;
	}
	public Collection<sgListValue> getZhlists() {
		return Zhlists;
	}
	public void setZhlists(Collection<sgListValue> zhlists) {
		Zhlists = zhlists;
	}
	
	public sgNewValue getSgnew() {
		return sgnew;
	}
	public void setSgnew(sgNewValue sgnew) {
		this.sgnew = sgnew;
	}
}